	import {
		getCode
	} from '@/utils/weixin.util.js'
	export default { // 导出混入对象
		data() {
			return {
				avatar: '',
				phoneNumber: '',
				phoneCode: '',
			}
		},
		methods: {
			// 微信授权登录
			decryptPhoneNumber(e) {
				if (!e.target.iv) {
					uni.showModal({
						content: '获取手机号失败！',
						showCancel: false
					})
					return;
				}
				this.phoneCode = e.detail.code
				wx.checkSession({
					success: (res) => {
						this.register()
					}
				})
			},
			// 登录请求接口
			register() {
				uni.showLoading({
					mask: true
				})
				getCode().then(code => {
					this.$post(`/auth/wxChat/register`, {
						code: code,
						phoneCode: this.phoneCode
					}).then((res) => {
						if (res.status) {
							this.login()
							return
						}
						console.log(res)
					})
				})
			},
			login() {
				getCode().then(code => {
					uni.showLoading({
						mask: true
					})
					this.$get(`/auth/wxChat/login`, {
						code: code
					}).then((res) => {
						console.log(88888888888888)
						console.log(res)
						if (res.status && res.data.data.login === true) {
							uni.setStorageSync('isRegister', true)
							uni.setStorageSync('account', res.data.data.userInfo.account)
							uni.setStorageSync('token', res.data.data.token)
							uni.setStorageSync('clientUserId', res.data.data.userInfo.id)
							uni.setStorageSync('avatar', res.data.data.userInfo.avatar)
							uni.setStorageSync('roles', res.data.data.roles)
							uni.setStorageSync('orgCategory', res.data.data.userInfo.orgCategory)
							uni.setStorageSync('userInfo', JSON.stringify(res.data.data.userInfo))
							this.loginSuccess(res)
							return
						}
						else if(res.status && res.data.data.login === false){
							this.isRegister = false
							uni.removeStorageSync('isRegister')
							uni.removeStorageSync('account')
							uni.removeStorageSync('token')
							uni.removeStorageSync('clientUserId')
							uni.removeStorageSync('avatar')
							uni.removeStorageSync('roles')
							uni.removeStorageSync('userInfo')
						}
					})
					this.loginFail();
				})
			},
			loginSuccess(res) {

			},
			loginFail() {

			},
			// // 登录请求接口
			// async login(code) {
			// 	const res = await this.$get(`/auth/wxChat/login`, {
			// 		code: code
			// 	})
			// 	console.log(res, 'res11111111111111');
			// 	if (res.status) {
			// 		uni.setStorageSync('account', res.data.data.userInfo.account)
			// 		uni.setStorageSync('token', res.data.data.token)
			// 		uni.setStorageSync('clientUserId', res.data.data.userInfo.id)
			// 		uni.setStorageSync('avatar', res.data.data.userInfo.avatar)
			// 		uni.setStorageSync('roles', res.data.data.roles)
			// 		this.phoneNumber = res.data.data.userInfo.account;
			// 		this.avatar = res.data.data.userInfo.avatar;
			// 		this.zhuCeShouQuan = false
			// 		uni.hideLoading()
			// 		// this.$ToastOk('登录成功')
			// 	}
			// },
		}
	}